#ifndef SLAVE_H_
#define SLAVE_H_
#include "server_conf.h"
#include "msg.h"

C_CODE_BEGIN

struct slave;
struct msgqueue;
struct slave_api;
struct master;

struct slave* _slave_load( const char* dlpath , struct slave_api* sapi, struct master* m );
void _slave_unload( struct slave* );
const char* _slave_name( struct slave* );
/* return value 0 means init function failed but do not call clean function automatically
 * <0 means error and the clean function will be invoked right after this failed call 
 * >0 means success. Nothing special will be done later. */
int _slave_init_invoke( struct slave* );
void _slave_clean_invoke( struct slave* );
void _slave_notification_invoke( struct slave* );
void _slave_cb_invoke( struct slave* , struct message* );
size_t _slave_new_sid( struct slave* );
struct msgqueue* _slave_ref_msgqueue( struct slave* );
struct slave_api* _slave_get_api( struct slave* );
struct master* _slave_api_ref_master( struct slave_api* );
struct slave* _slave_api_ref_slave( struct slave_api* );

/*
 * Slave replace function. This function is very interesting since it allows the user to replace the
 * related DLL entry function. This is typically used for reinstall certain slave . This function can
 * only change those entry function and it is not thread safe function. You should put it in a very 
 * elegant manner. 
 */

bool _slave_replace_load( struct slave* , const char* dlpath );
bool _slave_replace_compose( struct slave* );
/*
 * The following API is used to compose a slave manually .
 * This is typically for providing basic functionality , 
 * like Notification Slave which automatically dispatch
 * notification message to invoke the notification function
 * in a registered slave.
 * This kinds of slave is not load from dll(so) but compose
 * manually.
 */

struct slave* _slave_compose( struct slave_protocol* protocol , struct slave_api* sapi, struct master* m );
void _slave_destroy( struct slave* sl );

C_CODE_END

#endif // SLAVE_H_